import { VuexModule, Module, Action, getModule } from 'vuex-module-decorators'
import { getServers } from '@/api/server'
import store from '@/store'

export interface IServerState {

}

@Module({ dynamic: true, store, name: 'Server' })
class Server extends VuexModule implements IServerState {

    @Action
    public async getServers(menuId?: number) {
        return new Promise((r: any, j: any) => {
            let data = menuId ? { menuId: menuId } : null
            getServers().then((value: any) => {
                console.error("Server:", value)
                r(value.data)
            }).catch(ex => {
                console.error(ex);
                j([])
            })
        })
    }
}

export const ServerModule = getModule(Server)
